package com.example.travelservlet.likeDynamic.controller;

import com.example.travelservlet.entity.Like;
import com.example.travelservlet.entity.LikeDynamic;
import com.example.travelservlet.likeDynamic.service.LikeDynamicService;
import com.example.travelservlet.user.domain.Result;
import com.example.travelservlet.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

/**
 * @author hxy
 * @date 2023/5/19 10:05
 */
@RestController
@RequestMapping("/likeDynamicController")
public class LikeDynamicController {
    @Autowired
    private LikeDynamicService likeDynamicService;

    @GetMapping("/insertLikeDynamic/{userId}/{dynamicId}/{userName}")
    public Integer insertLikeDynamic(@PathVariable String userId, @PathVariable String dynamicId, @PathVariable String userName){
        LikeDynamic likeDynamic = new LikeDynamic();
        likeDynamic.setId(UUID.randomUUID().toString());
        likeDynamic.setDynamicId(dynamicId);
        likeDynamic.setUserId(userId);
        likeDynamic.setUserName(userName);
        Integer integer = likeDynamicService.insertLikeDynamic(likeDynamic);
        return integer;
    }

    @GetMapping("/deleteLikeDynamic/{userId}/{dynamicId}")
    public Integer deleteLikeDynamic(@PathVariable String userId,@PathVariable String dynamicId){
        Integer integer = likeDynamicService.deleteLikeDynamic(userId, dynamicId);
        return integer;
    }
    @GetMapping("/findLikeDynamicByDynamicId/{dynamicId}")
    public Result<List<LikeDynamic>> findLikeDynamicByDynamicId(@PathVariable String dynamicId){
        List<LikeDynamic> likeDynamicList = likeDynamicService.findLikeDynamicByDynamicId(dynamicId);
        return ResultUtil.success(likeDynamicList);
    }
}
